package com.xms.plugin.service;

import com.xms.plugin.entity.EntityPlugin;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URLClassLoader;

/**
 * <p>
 * EntityPluginFileProvider
 * </p>
 *
 * @author migo
 * @since 2021/10/15
 */
@Service
public class EntityPluginFileProvider implements IEntityPluginFileProvider {
    public void EntityPluginFileProvider() {

    }

    @Override
    public boolean loadAssembly(EntityPlugin entity) {
        return true;
    }

    /*private void addJarToClasspath(EntityPlugin plugin) {
        try {
            URL url = new URL(s);
				s = null;

				URLClassLoader myClassLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread()
						.getContextClassLoader());
				Class<? extends AbstractAction> myClass = (Class<? extends AbstractAction>) myClassLoader.loadClass("com.java.jarloader.TestAction");
				AbstractAction action = (AbstractAction) myClass.newInstance();
				String str = action.action();
				System.out.println(str);

				//第二种
				URL url1 = new URL("file:D:/jarload/test.jar");
				URLClassLoader myClassLoader1 = new URLClassLoader(new URL[] { url1 }, Thread.currentThread()
						.getContextClassLoader());
				Class<?> myClass1 = myClassLoader1.loadClass("com.java.jarloader.TestAction");
        } catch (IllegalAccessException | MalformedURLException | InvocationTargetException | NoSuchMethodException e) {
            throw new RuntimeException("添加插件jar包到classpath失败，插件名称：" + plugin.getName());
        }
    }*/
}
